//
//  YHOptionTitleContentPickerTableViewCell.m
//  ScriptKill
//
//  Created by 林宁宁 on 2021/4/28.
//  Copyright © 2021 优智汇. All rights reserved.
//

#import "YHOptionTitleTextInputTableViewCell.h"
#import "UIView+YHInputAccessory.h"
#import "NSMutableAttributedString+YH.h"

@implementation YHOptionTitleTextInputTableViewCell

-(void)yh_optionInit{
    
    self.cellTextFiled = [UITextField new];
    self.cellTextFiled.backgroundColor = [UIColor clearColor];
    self.cellTextFiled.textAlignment = NSTextAlignmentLeft;
    self.cellTextFiled.font = [UIFont yh_pfOfSize:14];
    self.cellTextFiled.clearButtonMode = UITextFieldViewModeNever;
    self.cellTextFiled.textColor = [UIColor yh_h2];
    
    [self.cellTextFiled showAccessoryDown:^{
            
    }];
    [self.cellTextFiled addTarget:self action:@selector(editChangeAction) forControlEvents:UIControlEventEditingChanged];
    [self.cellTextFiled addTarget:self action:@selector(editEndAction) forControlEvents:UIControlEventEditingDidEnd];
    [self.cellOptionContentView addSubview:self.cellTextFiled];
    [self.cellTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self.cellOptionContentView);
        make.left.equalTo(self.cellOptionContentView);
    }];
    
    WS(weakSelf)
    [self yh_kvoForKeyPath:@"placeholder" observe:self.cellTextFiled block:^(id  _Nonnull obj, id  _Nullable oldVal, id  _Nullable newVal) {
        weakSelf.cellTextFiled.attributedPlaceholder = [NSMutableAttributedString yh_initWithStr:weakSelf.cellTextFiled.placeholder customBlock:^(NSMutableAttributedString *att) {
            [att yh_font:[UIFont yh_pfOfSize:14]];
            [att yh_color:[UIColor yh_hint]];
        }];
    }];
}

- (void)editChangeAction{
    if(self.editChangeBlock){
        self.editChangeBlock(self.cellTextFiled.text, self);
    }
}

- (void)editEndAction{
    if(self.editEndBlock){
        self.editEndBlock(self.cellTextFiled.text, self);
    }
}

@end
